1. 字符串<->数组 互转

  • 字符串 -> 数组
x = '123'
list(x) # ['1', '2', '3']
x = '1,2,3'
x.split(',') # ['1', '2', '3']
  • 数组 -> 字符串
arr = ['a','b','c']
x = ''.join(arr)
x = ','.join(arr)

arr = [1,2,3]
x = ','.join(str(i) for i in arr) # 使用遍历强转元素格式
x = ''.join(arr) # 若列表中有数字类型,使用join(arr)报错

2. 字符串 -> 整型数组

x = '1 2 3' #有时候通过input输入
print(x.split()) # 元素类型为str:['1','2','3']
print(list(map(int, x.split()))) # 将字符串转数组元素类型改为int:[1,2,3]

3. 最大值

# 整数
import sys
MAX_INT = sys.maxsize
# 浮点数
MAX_FLOAT = float('inf') # float('-inf')
Copyright © 2021 zbmain.  all right reserved,powered by Gitbook本页修订时间: 2021-04-12

results matching ""

    No results matching ""